<template>
  <!-- 输入框 -->
  <header class="header">
    <h1>小黑记事本</h1>
    <input
      v-model="todoText"
      @keyup.enter="addTodo"
      placeholder="请输入任务"
      class="new-todo"
    />
    <button @click="addTodo" class="add">添加任务</button>
  </header>
</template>

<script>
export default {
  data() {
    return {
      todoText: "",
    };
  },
  methods: {
    addTodo() {
      if (this.todoText.trim() === "") {
        alert("请输入任务");
        return;
      }
      this.$emit("add", this.todoText);
      this.todoText = "";
    },
  },
};
</script>

<style>
</style>